package com.lonely.web.controller.inventory;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lonely.common.core.domain.Cascader;
import com.lonely.common.core.domain.Select;
import com.lonely.common.core.domain.api.R;
import com.lonely.inventory.domain.dto.storagearchive.BatchDeleteStorageArchiveDTO;
import com.lonely.inventory.domain.dto.storagearchive.PrintStorageCodeDTO;
import com.lonely.inventory.domain.dto.storagearchive.StorageArchivePageQueryDto;
import com.lonely.inventory.domain.dto.storagearchive.StorageArchiveSubmitDto;
import com.lonely.inventory.domain.vo.storagearchive.StorageArchivePageQueryVo;
import com.lonely.inventory.service.IStorageArchiveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 黄志标
 * @date: 2025/9/17 17:09
 * @description: 库位档案请求处理器
 */
@RestController
@RequestMapping("/inventoryManager/storageArchive")
@Api(tags = "库存管理/库位档案")
public class StorageArchiveController {

    @Autowired
    private IStorageArchiveService storageArchiveService;

    /**
     * 分页查询
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
    public R<Page<StorageArchivePageQueryVo>> page(@RequestBody StorageArchivePageQueryDto queryDto) {
        return R.data(this.storageArchiveService.page(queryDto));
    }


    /**
     * 创建库位并打印
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/saveAndPrint")
    @ApiOperation(value = "创建库位并打印")
    @SaCheckPermission("inventory:storageArchive:saveAndPrint")
    public R<String> saveAndPrint(@RequestBody @Validated List<StorageArchiveSubmitDto> submitDto) {
        return R.data(this.storageArchiveService.saveAndPrint(submitDto));
    }


    /**
     * 删除库位档案
     *
     * @param id
     * @return
     */
    @GetMapping("/deleteStorageArchive/{id}")
    @ApiOperation(value = "删除库位档案")
    @SaCheckPermission("inventory:storageArchive:deleteStorageArchive")
    public R<Boolean> deleteStorageArchive(@PathVariable("id") Long id) {
        this.storageArchiveService.deleteStorageArchive(id);
        return R.status(true);
    }


    /**
     * 打印库位码
     *
     * @param printStorageCodeDTO
     * @return
     */
    @PostMapping("/printStorageCode")
    @ApiOperation(value = "打印库位码")
    @SaCheckPermission("inventory:storageArchive:printStorageCode")
    public R<String> printStorageCode(@RequestBody @Validated PrintStorageCodeDTO printStorageCodeDTO) {
        return R.data(this.storageArchiveService.printStorageCode(printStorageCodeDTO));
    }


    /**
     * 批量删除库位档案
     *
     * @param batchDeleteStorageArchiveDTO
     * @return
     */
    @PostMapping("/batchDeleteStorageArchive")
    @ApiOperation(value = "批量删除库位档案")
    @SaCheckPermission("inventory:storageArchive:batchDeleteStorageArchive")
    public R<Boolean> batchDeleteStorageArchive(@RequestBody @Validated BatchDeleteStorageArchiveDTO batchDeleteStorageArchiveDTO) {
        this.storageArchiveService.batchDeleteStorageArchive(batchDeleteStorageArchiveDTO);
        return R.status(true);
    }

    /**
     * 获取库位码级联数据
     *
     * @return
     */
    @GetMapping("/getStorageCodeCascader")
    public R<List<Cascader>> getStorageCodeCascader() {
        return R.data(this.storageArchiveService.getStorageCodeCascader());
    }

    /**
     * 获取备货库存类型的库位列表
     *
     * @return
     */
    @GetMapping("/getStorageArchiveSelectByBhStorageType")
    public R<List<Select>> getStorageArchiveSelectByBhStorageType() {
        return R.data(this.storageArchiveService.getStorageArchiveSelectByBhStorageType());
    }
}
